<?php
namespace Home\Controller;
use Home\Controller\HomeController;
class ArtController extends HomeController {
    public function _initialize(){
        parent::_initialize();
    }
	//新闻资讯
	public function index(){
    	$page = I('page');
    	$num = I('num');
    	if(empty($page)){
    	    $page = 1;
    	}
    	if(empty($num)){
    	    $num = 10;
    	}
    	$where['a.status'] = 1;
    	$list = M('Article')
    	->alias('a')
    	->where($where)
    	->limit(($page-1)*$num,$num)
    	->order('add_time desc')
    	->select();
    	$count =  M('Article a')
    	->where($where)
    	->count();
    	$return['count'] = $count;
    	$return['data'] = $list;
    	$return['status'] = 1;
		$this->ajaxReturn($return);
     }
     /**
	 * 新闻详情
	 */
    public function details(){
    	$article = M('Article');
    	 $where['id'] = I('id');
		$art_one = $article->where($where)->find();
		$return['data'] = $art_one;
		$return['status'] = 1;
    	$this->ajaxReturn($return);
    }
    //消息列表
//     public function noticeList(){
//         $page = I('page');
//     	$num = I('num');
//     	if(empty($page)){
//     	    $page = 1;
//     	}
//     	if(empty($num)){
//     	    $num = 20;
//     	}
//     	$where['status'] = 1;
//     	$where['type'] = I('type')?I('type'):'1';
//     	//$language = $_SERVER['HTTP_LANGUAGE']?$_SERVER['HTTP_LANGUAGE']:'';
//     	$list = M('Notice')
//     	->alias('a')
//     	->where($where)
//     	->limit(($page-1)*$num,$num)
//     	->order('add_time desc')
//     	->select();
// //     	if($language){
// //     	    if($language=='ko'){
// //     	        $language='kor';
// //     	    }
// //     	    foreach ($list as $k=>$v){
// //         	    $lan = language($v['title'], 'zh', $language);
// //         	    foreach ($lan as $kk => $vv)
// //         	    {
// //         	        $list[$k]['title'] = ucwords($vv->dst) ."\n";
// //         	    }
// //     	    }
// //     	}
//     	$count =  M('Notice')
//     	->where($where)
//     	->count();
//     	$return['count'] = $count;
//     	$return['data'] = $list;
//     	$return['status'] = 1;
//         $this->ajaxReturn($return);
//     }
    /**
     * 公告详情
     */
    public function noticeDetails(){
        $language = $_SERVER['HTTP_LANGUAGE']?$_SERVER['HTTP_LANGUAGE']:'';
        //dump($language);
        $article = M('Notice');
        $where['id'] = I('id');
        $art_one = $article->where($where)->find();
        if($language){
            if($language=='ko'){
                $language='kor';
            }
             $lan = language($art_one['title'], 'zh', $language);
            foreach ($lan as $k => $v)
            {
                $art_one['title'] = ucwords($v->dst) ."\n";
            }
            $lan1 = language($art_one['content'], 'zh', $language);
            //dump($lan1);
            foreach ($lan1 as $k => $v)
            {
                $art_one['content'] = ucwords($v->dst) ."\n";
            }
        }
        $return['data'] = $art_one;
        $return['status'] = 1;
        $this->ajaxReturn($return);
    }
    //留言
}